#include "include\wrapper\cef_message_router.h"

#include "include/cef_task.h"
#include "include/cef_thread.h"
#include "include/base/cef_callback.h"
#include "include/base/cef_callback_helpers.h"

class SimpleBrowserSideHandler : public CefMessageRouterBrowserSide::Handler
{
	CefRefPtr<CefThread> _thread;
public:
	SimpleBrowserSideHandler(){
		_thread = CefThread::CreateThread("user_thread");
	}
	~SimpleBrowserSideHandler(){
		_thread->Stop();
	}

	static bool Query(CefRefPtr<CefBrowser> browser,
		const CefString& request,
		CefRefPtr<Callback> callback);

	virtual bool OnQuery(CefRefPtr<CefBrowser> browser,
		CefRefPtr<CefFrame> frame,
		int64 query_id,
		const CefString& request,
		bool persistent,
		CefRefPtr<Callback> callback);

	virtual void OnQueryCanceled(CefRefPtr<CefBrowser> browser,
		CefRefPtr<CefFrame> frame,
		int64 query_id);

	class CefTaskData : public CefTask {
		CefRefPtr<CefBrowser> _browser;
		const CefString _request;
		CefRefPtr<Callback> _callback;

		public:
			CefTaskData(CefRefPtr<CefBrowser> browser,const CefString request,CefRefPtr<Callback> callback):
				_browser(browser),_request(request),_callback(callback){}
			void Execute()override{SimpleBrowserSideHandler::Query(_browser,_request,_callback);}
		IMPLEMENT_REFCOUNTING(CefTaskData);
	};
};